package com.wyh.scheduled;

import com.wyh.domain.po.g3po.Charging;
import com.wyh.domain.po.g3po.G3Contract;
import com.wyh.mapper.g3mapper.G3ChargingMapper;
import com.wyh.service.g3service.ContractService;
import com.wyh.service.g3service.GenerateBillingContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: cc
 * @Date: 2024/05/21/9:27
 **/
@Component
public class MyScheduledTask {
    @Autowired
    private ContractService g3ContractService;
    @Autowired
    private GenerateBillingContent generateBillingContent;
    @Autowired
    G3ChargingMapper g3ChargingMapper;
    @Scheduled(cron = "0 0 0 1 * ?")
    public void Timing() {
        //查询所有合同
        List<G3Contract> g3ContractList =new ArrayList<>();
        g3ContractList =g3ContractService.getAllContracts();
        //对每份合同下的所有计费项（正常）进行检索
        for (G3Contract g3Contract : g3ContractList) {
            //计费项生成
            List<Charging> chargingList=generateBillingContent.GenerateBilling(g3Contract);
            //将每个计费项添加到数据库
            for (Charging charging:chargingList) {
                g3ChargingMapper.insertCharging(charging);
            }
        }
    }
}
